import java.util.Iterator;
import java.util.LinkedList;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;

/**
 *    class for global functions and varibles 
 */
public class Global {
	
	public static ClientConsole chat;
	public static JFrame main;
	public static JPanel back;
	public static String sem;
	public static Login logIn;
	public static JPanel mainPanel;
	
	
	public Global (JFrame frame,JPanel panel){
		
		main = frame;
		mainPanel = panel;
	}
	
	public static void showMain(){
		mainPanel.setVisible(true);
		main.setContentPane(mainPanel);
	}
	
	public static void logOut()
	{
		SQL s = new SQL (Global.logIn,21);
		s.accept();
	}
	public static void StatShow(String output, int x, int y,String Title)
	{
		JTextArea outputArea = new JTextArea( x, y );
		outputArea.setText( output );
		JOptionPane.showMessageDialog( null, outputArea, Title ,JOptionPane.INFORMATION_MESSAGE );
	}
	
	public static String SetOutput(Object[] sql)
	{
		SQL s1 = new SQL(sql,95);
		s1.accept();
		Object msg = s1.getMsg();
		LinkedList<GQuery> list = (LinkedList<GQuery>) msg; 
		Iterator<GQuery> itr = list.iterator();
		
		LinkedList<GQuery> Histo = new LinkedList<GQuery>();
		while (itr.hasNext())
		{
			GQuery G = itr.next();
			Histo.add(G);		
		}
		String output = "";

		output += "ID\tAverage\tHistogram";
		Iterator<GQuery>itrAVG = Histo.iterator();
		while (itrAVG.hasNext())
		    {
		    	GQuery G = itrAVG.next();
		    	output += "\n" + G.getID() + "\t" + G.getAvg() + "\t";
		   
		    	for ( int j = 1; j <= G.getAvg(); j++ ) // print a bar
		    		output += "*";
		    }
		output += "\n\nID\tMAX\tHistogram";
		Iterator<GQuery>itrMAX = Histo.iterator();
		while (itrMAX.hasNext())
		    {
		    	GQuery G = itrMAX.next();
		    	output += "\n" + G.getID() + "\t" + G.getMax() + "\t";
		   
		    	for ( int j = 1; j <= G.getMax(); j++ ) // print a bar
		    		output += "*";
		    }
		output += "\n\nID\tMIN\tHistogram";
		Iterator<GQuery>itrMIN = Histo.iterator();
		while (itrMIN.hasNext())
		    {
		    	GQuery G = itrMIN.next();
		    	output += "\n" + G.getID() + "\t" + G.getMin() + "\t";
		   
		    	for ( int j = 1; j <= G.getMin(); j++ ) // print a bar
		    		output += "*";
		    }
		output += "\n\nID\tCount\tHistogram";
		Iterator<GQuery>itrCount = Histo.iterator();
		while (itrCount.hasNext())
		    {
		    	GQuery G = itrCount.next();
		    	output += "\n" + G.getID() + "\t" + G.getCount() + "\t";
		   
		    	for ( int j = 1; j <= G.getCount(); j++ ) // print a bar
		    		output += "*";
		    }
		return output;
	}
}


